package com.shqcjd.sinopecdemomobile.ui.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shqcjd.sinopecdemomobile.R;
import com.shqcjd.sinopecdemomobile.model.pojo.PopKnowledgeBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class KnowledgePopAdapter extends BaseQuickAdapter<PopKnowledgeBean,KnowledgePopAdapter.ViewHolder> {
    private Context context;
    private List<PopKnowledgeBean> data;
    public KnowledgePopAdapter(@Nullable List<PopKnowledgeBean> data, Context context) {
        super(R.layout.pop_knowledge_item, data);
        this.context = context;
        this.data = data;
    }

    @Override
    protected void convert(KnowledgePopAdapter.ViewHolder helper, PopKnowledgeBean item) {
        helper.cb_pop_knowledge_item.setText(item.name);
        helper.cb_pop_knowledge_item.setChecked(item.isCheck);
        helper.cb_pop_knowledge_item.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                data.get(helper.getAdapterPosition()).isCheck = isChecked;
            }
        });
    }

    public void resetCheckList(){
        for(int i=0; i<data.size(); i++){
            data.get(i).isCheck = false;
        }
        notifyDataSetChanged();
    }

    public List<PopKnowledgeBean> getMyData(){
        return data;
    }

    class ViewHolder extends BaseViewHolder {
        @BindView(R.id.cb_pop_knowledge_item)
        CheckBox cb_pop_knowledge_item;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
